home *** CD-ROM | disk | FTP | other *** search
- /*
- ** WarpOS exception handler demo
- */
-
- #include <stdio.h>
-
- #include <utility/tagitem.h>
- #include <powerpc/powerpc.h>
- #include <powerpc/tasksPPC.h>
- #include <clib/powerpc_protos.h>
-
-
- static ULONG sigmask;
- static struct TaskPPC *mytask;
- static struct EXCContext exc;
-
-
- ULONG getR2(void) = "\tmr\tr3,r2";
- static ULONG exception_handler(struct EXCContext *);
-
-
-
- main()
- {
- struct TagItem ehtags[] = {
- { EXCATTR_CODE,(ULONG)exception_handler },
- { EXCATTR_DATA,0 },
- { EXCATTR_EXCID,EXCF_MCHECK | EXCF_DACCESS | EXCF_IACCESS |
- EXCF_PROGRAM | EXCF_ALIGN },
- { EXCATTR_FLAGS,EXCF_GLOBAL | EXCF_LARGECONTEXT },
- { EXCATTR_NAME,(ULONG)"Test-Handler" },
- { TAG_DONE }
- };
- LONG sig;
- void *xlock;
- int i;
-
- ehtags[1].ti_Data = getR2();
- mytask = FindTaskPPC(NULL);
- if ((sig = AllocSignalPPC(-1)) < 0)
- exit(10);
- sigmask = 1<<sig;
-
- if (xlock = SetExcHandler(ehtags)) {
- printf("Exception handler installed.\n\n");
- WaitPPC(sigmask);
- RemExcHandler(xlock);
-
- printf("Exception type %ld occured at PC=0x%08lx!\nGPR-dump:\n",
- exc.ec_ExcID,exc.ec_UPC.ec_PC);
- for (i=0; i<32; i+=8)
- printf("GPR%02d-%02d %08lx %08lx %08lx %08lx %08lx %08lx %08lx "
- "%08lx\n",i,i+7,exc.ec_GPR[i],exc.ec_GPR[i+1],exc.ec_GPR[i+2],
- exc.ec_GPR[i+3],exc.ec_GPR[i+4],exc.ec_GPR[i+5],
- exc.ec_GPR[i+6],exc.ec_GPR[i+7]);
- }
-
- FreeSignalPPC(sig);
- exit(0);
- }
-
-
- static ULONG exception_handler(struct EXCContext *ec)
- {
- memcpy(&exc,ec,sizeof(struct EXCContext));
- SignalPPC(mytask,sigmask);
- return (EXCRETURN_NORMAL);
- }
-